// api/order_api/order_list.go
package order_api

import (
	"github.com/gin-gonic/gin"
	"muziai-server/global"
	"muziai-server/models"
	"muziai-server/models/ctype"
	"muziai-server/utils/jwts"
	"muziai-server/utils/res"
)

type OrderStatusRequest struct {
	No string `json:"no" form:"no" binding:"required"`
}

type OrderStatusResponse struct {
	PayStatus ctype.PayStatusType `json:"payStatus"` // 1未支付 2支付成功 3 支付超时 4
}

func (OrderApi) OrderStatusView(c *gin.Context) {
	var cr OrderStatusRequest
	err := c.ShouldBindQuery(&cr)
	if err != nil {
		res.FailWithError(c, err)
		return
	}
	_claims, _ := c.Get("claims")
	claims := _claims.(*jwts.Claims)
	query := global.DB.Where("")

	if claims.IsAuth() {
		query.Where("user_id = ?", claims.UserID)
	}

	var order models.OrderModel
	err = global.DB.Debug().Where(query).Take(&order, "no=?", cr.No).Error
	if err != nil {
		res.FailWithMsg(c, "订单不存在")
		return
	}
	res.OkWithData(c, OrderStatusResponse{
		PayStatus: order.PayStatus,
	})
}
